//
//  DeviceInfo.h
//  MusicAnalyzer
//
//  Created by jiro on 12/03/23.
//  Copyright 2012 jiro music. All rights reserved.
//

#pragma once

#import "../DeviceInfo.h"
#import <string>
#import <sstream>

namespace sc
{

class UsbDeviceInfo : virtual public DeviceInfo
{
private:

	uint16_t vendorId;		//	field for reduce communication to device

	uint16_t productId;		//	field for reduce communication to device

	std::string vendorName;

	std::string productName;

public:

	UsbDeviceInfo()
		: DeviceInfo(),
		  vendorId( 0x00 ),
		  productId( 0x00 ),
		  vendorName( "" ),
		  productName( "" )
	{
		SetType( DeviceInfo::Type_UsbDevice );
	}

	UsbDeviceInfo( uint16_t vendorId, uint16_t productId, const std::string& vendorName, const std::string& productName )
		: DeviceInfo(),
		  vendorId( vendorId ),
		  productId( productId ),
		  vendorName( vendorName ),
		  productName( productName )
	{
		SetType( DeviceInfo::Type_UsbDevice );
	}
	
	UsbDeviceInfo( const UsbDeviceInfo& info )
		: DeviceInfo(),
		  vendorId( info.vendorId ),
		  productId( info.productId ),
		  vendorName( info.vendorName ),
		  productName( info.productName )
	{
		SetType( DeviceInfo::Type_UsbDevice );
	}
	
	virtual ~UsbDeviceInfo() {}

	//	---- query selction ---- //
	uint16_t GetVendorId() const { return vendorId; }

	uint16_t GetProductId() const { return productId; }

	std::string GetVendorName() const { return vendorName; }

	std::string GetProductName() const { return productName; }

	bool HasSameIds( uint16_t vendorIdArg, uint16_t productIdArg ) const
	{
		if ( ( GetVendorId() == vendorIdArg ) and ( GetProductId() == productIdArg ) )
		{
			return true;
		}
		return false;
	}

	virtual bool IsUsbDevice() const { return true; }

	bool operator < ( const UsbDeviceInfo& info ) const 
	{
		if ( vendorId != info.vendorId )
		{
			return vendorId < info.vendorId;
		}
		if ( productId != info.productId )
		{
			return productId < info.productId;
		}
		return false;
	}

	std::string ToString( int tabCount = 0 ) const
	{
		std::string tabs;
		for ( int i = 0; i < tabCount; i++ )
		{
			tabs.append( "\t" );
		}
		
		std::stringstream ss;
		ss << tabs << DeviceInfo::ToString() << ": "
			<< GetVendorName() << "(" << std::hex << GetVendorId() << "), "
			<< GetProductName() << "(" << std::hex << GetProductId() << ")";
		return ss.str();
	}
	//	------------------------ //

};

}